BX.namespace("BX.UI");if(typeof BX.UI.EntityEditorFieldSelector==="undefined"){BX.UI.EntityEditorFieldSelector=function(){this._id="";this._settings={};this._scheme=null;this._excludedNames=null;this._contentWrapper=null;this._popup=null;this.fieldVisibleClass="ui-entity-editor-popup-field-search-list-item-visible";this.fieldHiddenClass="ui-entity-editor-popup-field-search-list-item-hidden"};BX.UI.EntityEditorFieldSelector.prototype={initialize:function(e,t){this._id=e;this._settings=t?t:{};this._scheme=BX.prop.get(this._settings,"scheme",null);if(!this._scheme){throw"BX.UI.EntityEditorFieldSelector. Parameter 'scheme' is not found."}this._excludedNames=BX.prop.getArray(this._settings,"excludedNames",[])},getMessage:function(e){return BX.prop.getString(BX.UI.EntityEditorFieldSelector.messages,e,e)},isSchemeElementEnabled:function(e){var t=e.getName();for(var i=0,n=this._excludedNames.length;i<n;i++){if(this._excludedNames[i]===t){return false}}return true},addClosingListener:function(e){BX.Event.EventEmitter.subscribe("BX.UI.EntityEditorFieldSelector:close",e)},removeClosingListener:function(e){BX.Event.EventEmitter.unsubscribe("BX.UI.EntityEditorFieldSelector:close",e)},isOpened:function(){return this._popup&&this._popup.isShown()},open:function(){if(this.isOpened()){return}this._popup=new BX.PopupWindow(this._id,null,{autoHide:false,draggable:true,bindOptions:{forceBindPosition:false},closeByEsc:true,closeIcon:{},zIndex:1,titleBar:BX.prop.getString(this._settings,"title",""),content:this.prepareContent(),lightShadow:true,contentNoPaddings:true,buttons:[new BX.PopupWindowButton({text:BX.message("UI_ENTITY_EDITOR_SELECT"),className:"ui-btn ui-btn-success",events:{click:BX.delegate(this.onAcceptButtonClick,this)}}),new BX.PopupWindowButtonLink({text:BX.message("UI_ENTITY_EDITOR_CANCEL"),className:"ui-btn ui-btn-link",events:{click:BX.delegate(this.onCancelButtonClick,this)}})],events:{onPopupClose:this.onPopupClose.bind(this)}});this._popup.show()},close:function(){if(!(this._popup&&this._popup.isShown())){return}this._popup.close()},prepareContent:function(){this._contentWrapper=BX.create("div",{props:{className:"ui-entity-editor-popup-field-selector"}});var e=BX.prop.getString(this._settings,"useFieldsSearch",false);if(e){var t=BX.create("div",{attrs:{className:"ui-entity-editor-popup-field-search-header-wrapper"},children:[BX.create("div",{attrs:{className:"ui-form-row-inline"}})]});this._contentWrapper.prepend(t);this.prepareContentHeaderSections(t);this.prepareContentHeaderSearch(t)}var i=BX.create("div",{props:{className:"ui-entity-editor-popup-field-selector-list"}});var n=this._scheme.getElements();for(var s=0,r=n.length;s<r;s++){var o=n[s];var l=o.getElements();for(var a=0,c=l.length;a<c;a++){var p=l[a];if(!this.isSchemeElementEnabled(p)){continue}var d=[];var u=p.getElements();var h;for(var f=0;f<u.length;f++){h=u[f];if(h.isTransferable()&&h.getName()!==""){d.push(h)}}if(d.length===0){continue}var m=p.getName();var B=p.getTitle();i.appendChild(BX.create("div",{attrs:{className:"ui-entity-editor-popup-field-selector-list-caption"},text:B}));var g=BX.create("div",{attrs:{className:"ui-entity-editor-popup-field-selector-list-section"}});i.appendChild(g);for(var f=0;f<d.length;f++){h=d[f];var X=h.getName();var E=h.getTitle();var v=m+"\\"+X;var S=BX.create("div",{attrs:{className:"ui-entity-editor-popup-field-selector-list-item"}});g.appendChild(S);S.appendChild(BX.create("input",{attrs:{id:v,type:"checkbox",className:"ui-entity-editor-popup-field-selector-list-checkbox"}}));S.appendChild(BX.create("label",{attrs:{for:v,className:"ui-entity-editor-popup-field-selector-list-label"},text:E}))}}}this._contentWrapper.appendChild(i);return this._contentWrapper},prepareContentHeaderSections:function(e){var t=BX.create("div",{attrs:{className:"ui-form-row"},children:[BX.create("div",{attrs:{className:"ui-form-content ui-entity-editor-popup-field-search-section-wrapper"}})]});e.firstElementChild.appendChild(t);var i=BX.prop.getString(this._settings,"buttonTitle","");var n="ui-entity-editor-popup-field-search-section-item-icon ui-entity-editor-popup-field-search-section-item-icon-active";var s=BX.create("div",{attrs:{className:"ui-entity-editor-popup-field-search-section-item"},children:[BX.create("div",{attrs:{className:n},html:i})]});t.firstElementChild.appendChild(s)},prepareContentHeaderSearch:function(e){var t=BX.create("input",{attrs:{className:"ui-ctl-element ui-entity-editor-popup-field-search-section-input"},events:{input:this.onFilterSectionSearchInput.bind(this)}});var i=BX.create("div",{attrs:{className:"ui-form-row"},children:[BX.create("div",{attrs:{className:"ui-form-content ui-entity-editor-popup-field-search-input-wrapper"},children:[BX.create("div",{attrs:{className:"ui-ctl ui-ctl-textbox ui-ctl-before-icon ui-ctl-after-icon"},children:[BX.create("div",{attrs:{className:"ui-ctl-before ui-ctl-icon-search"}}),BX.create("button",{attrs:{className:"ui-ctl-after ui-ctl-icon-clear"},events:{click:this.onFilterSectionSearchInputClear.bind(this,t)}}),t]})]})]});e.firstElementChild.appendChild(i)},onFilterSectionSearchInput:function(e){var t=e.target?e.target.value:e.value;if(t.length){t=t.toLowerCase()}this.getFieldsPopupItems().map(function(e){var i=e.innerText.toLowerCase();if(t.length&&i.indexOf(t)===-1){BX.removeClass(e,this.fieldVisibleClass);BX.addClass(e,this.fieldHiddenClass)}else{BX.removeClass(e,this.fieldHiddenClass);BX.addClass(e,this.fieldVisibleClass);e.style.display="block"}}.bind(this))},getFieldsPopupItems:function(){if(!BX.type.isArray(this.fieldsPopupItems)){this.fieldsPopupItems=Array.from(this._contentWrapper.querySelectorAll(".ui-entity-editor-popup-field-selector-list-item"));this.prepareAnimation()}return this.fieldsPopupItems},prepareAnimation:function(){this.fieldsPopupItems.map(function(e){BX.bind(e,"animationend",this.onAnimationEnd.bind(this,e))}.bind(this))},onAnimationEnd:function(e){e.style.display=BX.hasClass(e,this.fieldHiddenClass)?"none":"block"},onFilterSectionSearchInputClear:function(e){if(e.value.length){e.value="";this.onFilterSectionSearchInput(e)}},getSelectedItems:function(){if(!this._contentWrapper){return[]}var e=[];var t=this._contentWrapper.querySelectorAll("input.ui-entity-editor-popup-field-selector-list-checkbox");for(var i=0,n=t.length;i<n;i++){var s=t[i];if(s.checked){var r=s.id.split("\\");if(r.length>=2){e.push({sectionName:r[0],fieldName:r[1]})}}}return e},onAcceptButtonClick:function(){BX.Event.EventEmitter.emit("BX.UI.EntityEditorFieldSelector:close",{sender:this,isCanceled:false,items:this.getSelectedItems()});this.close()},onCancelButtonClick:function(){BX.Event.EventEmitter.emit("BX.UI.EntityEditorFieldSelector:close",{sender:this,isCanceled:true});this.close()},onPopupClose:function(){if(this._popup){this._contentWrapper=null;this._popup.destroy()}},onPopupDestroy:function(){if(!this._popup){return}this._contentWrapper=null;this._popup=null}};if(typeof BX.UI.EntityEditorFieldSelector.messages==="undefined"){BX.UI.EntityEditorFieldSelector.messages={}}BX.UI.EntityEditorFieldSelector.create=function(e,t){var i=new BX.UI.EntityEditorFieldSelector(e,t);i.initialize(e,t);return i}}if(typeof BX.UI.EntityEditorUserSelector==="undefined"){BX.UI.EntityEditorUserSelector=function(){this._id="";this._settings={}};BX.UI.EntityEditorUserSelector.prototype={initialize:function(e,t){this._id=e;this._settings=t?t:{};this._isInitialized=false;this._onlyUsers=BX.prop.getBoolean(this._settings,"onlyUsers",true)},getId:function(){return this._id},open:function(e){if(this._mainWindow&&this._mainWindow===BX.SocNetLogDestination.containerWindow){return}if(!this._isInitialized){BX.SocNetLogDestination.init({name:this._id,extranetUser:false,userSearchArea:"I",bindMainPopup:{node:e,offsetTop:"5px",offsetLeft:"15px"},callback:{select:BX.delegate(this.onSelect,this),unSelect:BX.delegate(this.onSelect,this)},showSearchInput:BX.prop.getBoolean(this._settings,"showSearchInput",true),departmentSelectDisable:this._onlyUsers?true:false,items:{users:BX.UI.EntityEditorUserSelector.users,groups:{},sonetgroups:this._onlyUsers?{}:BX.UI.EntityEditorUserSelector.socnetGroups,department:BX.UI.EntityEditorUserSelector.department,departmentRelation:BX.SocNetLogDestination.buildDepartmentRelation(BX.UI.EntityEditorUserSelector.department)},itemsLast:BX.UI.EntityEditorUserSelector.last,itemsSelected:BX.prop.getObject(this._settings,"itemsSelected",{}),isCrmFeed:false,useClientDatabase:false,destSort:{},allowAddUser:false,allowSearchCrmEmailUsers:false,allowUserSearch:true});this._isInitialized=true}BX.SocNetLogDestination.openDialog(this._id,{bindNode:e});this._mainWindow=BX.SocNetLogDestination.containerWindow},close:function(){if(this._mainWindow&&this._mainWindow===BX.SocNetLogDestination.containerWindow){BX.SocNetLogDestination.closeDialog();this._mainWindow=null;this._isInitialized=false}},onSelect:function(e,t,i,n){if(this._onlyUsers&&t!=="users"){return}var s=BX.prop.getFunction(this._settings,"callback",null);if(s){s(this,e)}}};BX.UI.EntityEditorUserSelector.items={};BX.UI.EntityEditorUserSelector.create=function(e,t){var i=new BX.UI.EntityEditorUserSelector(e,t);i.initialize(e,t);this.items[i.getId()]=i;return i}}
//# sourceMappingURL=field-selector.map.js